/**
 * Created by pan on 2018年02月07日14:25:32.
 * @url 小说章节链接
 */
const express = require('express');
const router = express.Router();
const superagent = require('superagent');

const fetchData = url => {
    return new Promise(resolve => {
        resolve(
            superagent.get(`http://chapter2.zhuishushenqi.com/chapter/${url}`)
        );
    });
};

router.get('/', async function(req, res, next) {
    if (req.query.url) {
        const result = await fetchData(req.query.url);
        const { body } = result;
        res.json({
            result: 1,
            data: body.chapter,
        });
    } else {
        res.send({
            result: 0,
            msg: '参数错误',
        });
    }
});

module.exports = router;
